package cn.intotw.rdcj.core.config;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

/**
 * @Descripition:
 * @Author: chenxiang
 * @Date: 2017/10/12 19:55
 */
@Configuration
@EnableSwagger2
@EnableAutoConfiguration
public class Swagger2Config {

    @Bean
    public Docket createRestWeb() {
        //add by chenxiang v1.0.0 2020/4/24 如果需要在swagger定义头里的必填参数的话，要在这里定义，比如token之类的
        List<Parameter> headerParameters = new ArrayList<Parameter>();

//        ParameterBuilder parameter1 = new ParameterBuilder();
//        parameter1.name("Authorization").description("token").defaultValue("请先进行登录操作，获取token")
//                .modelRef(new ModelRef("string")).parameterType("header").required(true).build();
//        headerParameters.add(parameter1.build());

        return new Docket(DocumentationType.SWAGGER_2)
                .globalOperationParameters(headerParameters)
                .apiInfo(internalApiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("cn.intotw.rdcj"))
                .paths(PathSelectors.any())
                .build();
    }


    private ApiInfo internalApiInfo(){
        return new ApiInfoBuilder()
                .title("rdcj系统接口")
                .description("本文档包含了rdcj系统接口")
                .version("1.0.0")
                .build();

    }
}
